//涉及到博文的一些方法
/*
 * 博文顶、踩的功能
 */
function avatarInfo(){
	 /*
	    * 头像信息提醒功能,不足的是没有使用事件委托  live，blind等等
	    */
		$('.blog-avatar').each(function() { 
			$(this).qtip(
							{
								content : {
									// 设置您要使用的文字图像的HTML字符串，正确的src URL加载图像
									text : '<img class="throbber" src="'+ctx+'/img/loading.gif" alt="Loading..." />',
									url : $(this).attr('rel'), // 使用的URL加载的每个元素的rel属性
									title : {
										text : $(this).attr("title"), // 给工具提示使用每个元素的文本标题
										button : '_' // 在标题中显示关闭文字按钮
									}
								},
								position : {
									corner : {
										target : 'bottomMiddle', // 定位上面的链接工具提示
										tooltip : 'topMiddle'
									},
									adjust : {
										screen : true
									// 在任何时候都保持提示屏幕上的
									}
								},
								show : {
									when : 'mouseover', //或click 
									solo : true
								// 一次只显示一个工具提示
								},
								hide : 'unfocus',
								style : {
									tip : true, // 设置一个语音气泡提示在指定工具提示角落的工具提示
									border : {
										width : 0,
										radius : 4
									},
									name : 'light', // 使用默认的淡样式
									width : 390
								// 设置提示的宽度
								}
							});
		});
}
function digg(username, articleId, topNumber, stepNumber, flag) {
		var action = "top";
		if (flag)
			action = "step";

		if (topNumber == null)
			topNumber = 0;
		if (stepNumber == null)
			stepNumber = 0;

		$.ajax({
					url : ctx+"/blog/blog.action",
					type : "post",
					dataType : "json",
					data : {
						"topStep.username" : username,
						"topStep.articleId" : articleId,
						"topStep.action" : action,
						"method:saveTS" : "wwwww"
					},
					success : function() {

						$("#show-" + articleId).css("display", "none");
						$("#hidden-" + articleId).css("display", "block");
						if (flag) {
							html = "<span style='color: red;'><strong>"
									+ (topNumber * 1)
									+ "</strong>&nbsp;&nbsp;&nbsp;顶&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
							html = html
									+ "<span style='color:rgb(21, 80, 233);'><strong>"
									+ (stepNumber * 1 + 1)
									+ "</strong>&nbsp;&nbsp;&nbsp;踩&nbsp;&nbsp;</span>";
						} else {
							html = "<span style='color: red;'><strong>"
									+ (topNumber * 1 + 1)
									+ "</strong>&nbsp;&nbsp;&nbsp;顶&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
							html = html
									+ "<span style='color:rgb(21, 80, 233);'><strong>"
									+ (stepNumber * 1)
									+ "</strong>&nbsp;&nbsp;&nbsp;踩&nbsp;&nbsp;</span>";
						}
						$("#hidden-" + articleId).html(html);

					},
					error : function() {
						alert("ajax 传输错误！！！");
					},
					complete : function() {
					}
				});
	}

/*
 * 博文alt + enter自动回复功能实现
 */
function isKeyTrigger(e, keyCode) {
	var argv = isKeyTrigger.arguments;
	var argc = isKeyTrigger.arguments.length;
	var bCtrl = false;
	if (argc > 2) {
		bCtrl = argv[2];
	}
	var bAlt = false;
	if (argc > 3) {
		bAlt = argv[3];
	}

	var nav4 = window.Event ? true : false;

	if (typeof e == 'undefined') {
		e = event;
	}

	if (bCtrl&& !((typeof e.ctrlKey != 'undefined') ? e.ctrlKey: e.modifiers & Event.CONTROL_MASK > 0)) {
		return false;
	}
	if (bAlt&& !((typeof e.altKey != 'undefined') ? e.altKey : e.modifiers& Event.ALT_MASK > 0)) {
		return false;
	}
	var whichCode = 0;
	if (nav4)
		whichCode = e.which;
	else if (e.type == "keypress" || e.type == "keydown")
		whichCode = e.keyCode;
	else
		whichCode = e.button;

	return (whichCode == keyCode);
}

function ctrlEnter(inp, e) {                                //将input本身的参数传入
	var ie = navigator.appName == "Microsoft Internet Explorer" ? true: false;
	if (ie) {
		if (event.ctrlKey && window.event.keyCode == 13) {
			SubmitReply(inp);
		}
	} else {
		if (isKeyTrigger(e, 13, true)) {
			SubmitReply(inp);
		}
	}
}

function SubmitReply(inp) { //保存博文的回复操作回复

	var _input = $(inp);
	var articleId = _input.attr("data-nid");
	var content = _input.val();

	if (content.length <= 1) {
		alert('回复太短，请至少输入一个词组......');
		_input.focus();
		return;
	}

	//对content进行处理
	content = content.replace(/\w*@(\S+)\s/g,"<a href='javascript:void(0);' target='_blank'  title='$1'  class='blog-avatar' "
	                                          + " rel='${ctx }/widgets/avatarInfo.jsp?userName=$1'>@$1</a>");

	$.ajax({
		url : ctx+"/blog/blog.action",
		type : "post",
		data : {
			articleId : articleId,
			articleCommentContent : content,
			"method:saveArticleComment" : "www"
		},
		success : function(data) {

			_input.val("").focus();
			eval(' source = ' + data.toString());
			$.post(ctx+"/common/RequestComments.jsp", {
				"actionSerial" : 2,
				"articleCommentId" : source.articleCommentId,
				"description" : "根据博文回复的Id获取单条回复信息"
			}, function(data2) {
				$("[data-nid='feed-rep-content-" + articleId + "']").prepend(data2);
			});

		}
	});
}


function  readyArticle(){
   
	
	/*
	 * 博文删除
	 */
	$(".feed-del").live("click",function() {
			var msg = "您真的确定要删除吗？\n\n请确认！";
			if (confirm(msg)) { //进行删除操作
				var articleId = parseInt($(this).attr("data-articleId"));
				$(".feed-photo[data-articleId="+ articleId+ "]").fadeOut("slow"); //非真正从DOM树中进行了删除
				$.post(
						ctx+"/common/ProcessingClass.jsp",
						{
							"actionSerial" : 0,
							"articleId" : articleId,
							"description" : "博文删除的操作"
						},
						function(data) {
							alert("删除成功!!!!");
						});
			}
		});
    
	/*
     * 博文的回应
    */
	$(".feed-cmt").live("click",function() {
			var status = parseInt($(this).attr("data-status"));
			if (status == 0) {
				var articleId = parseInt($(this).attr("data-articleId"));
				$(".feed-cmt[data-articleId="+ articleId+ "]").text("收起").attr("data-status", "1");

				$.post(ctx+"/common/RequestComments.jsp",
								{
									"actionSerial" : 0,
									"articleId" : articleId,
									"description" : "根据博文Id获取回复信息"
								},
								function(data) {
									$("[data-nid='feed-com-"+ articleId+ "']").slideDown();
									$("[data-nid='feed-rep-content-"+ articleId	+ "']").html(data);

								});

			} else if (status == 1) { //说明已经展开
				var articleId = parseInt($(this).attr("data-articleId"));
				$(".feed-cmt[data-articleId="	+ articleId+ "]").text("回应").attr("data-status", "0");

				var _commnent = $("[data-nid='feed-com-"+ articleId+ "']").find(".feed-rep-more-button");
				_commnent.attr("data-current-numbers","3").attr("value","获取更多数据"); //回复数据

				$("[data-nid='feed-com-"+ articleId+ "']").slideUp();
			}

		});

	/*
	 * 博文添加收藏、取消收藏
	 */
	$(".mark-star").live("click",function() {
			var status = parseInt($(this).attr("data-status"));
			if (status == 0) {
				$(this).attr("src",ctx+"/img/star_on.gif");
				$(this).attr("data-status","1");
			} else {
				$(this).attr("src",ctx+"/img/star_off.gif");
				$(this).attr("data-status","0");
			}
			$.post(
				ctx+"/common/ProcessingClass.jsp",
				{
					"actionSerial" : 1,
					"articleId" : parseInt($(this).attr("data-articleId")),
					status : status,
					"description" : "博文的关注、取消关注的操作"
				}, function(data) {
				});
		});

	
	/*
	 * 博文的回复获取更多
	 */  
	$(".feed-rep-more-button").live("click",function() {
			var _this = $(this);
			var articleId = parseInt(_this.attr("data-articleId"));
			var currentNumbers = parseInt(_this.attr("data-current-numbers")); //已经加载了多少条数据
			_this.attr("data-current-numbers",(parseInt(_this.attr("data-current-numbers")) + 3)+ "");

			$.post(ctx+"/common/RequestComments.jsp",
							{
								"actionSerial" : 1,
								"articleId" : articleId,
								"currentNumbers" : currentNumbers,
								"description" : "根据博文Id和起始数据获取数据获取回复信息"
							},
							function(data) {
								if (data.indexOf("method:previewPic") > 0)
									$("[data-nid='feed-rep-content-"+ articleId+ "']").append(data);
								else
									_this.val("已经没有回复了..........");
							});

		});

	/*
	 * 博文回复鼠标滑过效果
	 */
	$("[id^='feed-nupt-rep-content-']")
	        .live("mouseover",function() {$(this).attr("style",	"padding: 5px 1px;-webkit-box-shadow: 0 -1px 30px #B0B3BB;-moz-box-shadow: 0 -1px 30px #B0B3BB;"
												+ "box-shadow: 0 -1px 30px #B0B3BB;");
					})
			.live("mouseout", function() {
				$(this).attr("style", "padding: 5px 1px;");

			})
			.live("dblclick",function() { //双击回复某人
						var articleId = $(this).attr("data-articleId");
						//  var articleCommentId = $(this).attr("id").match(/(\D*)(\d*)/)[2];
						var _input = $(".feed-comment-input[data-nid="+ articleId + "]");

						//获取用户的姓名信息
						var _p1 = $(this).find("div");
						var avatar = _p1.find(".feed-rep-avatar");
						var username = avatar.find("img").attr("title").replace(/[\t\n\r\f]/, "").replace(' ', "");

						_input.val("@" + username + " :").focus();
			});


	
}